package com.lhd.web.admin;

import com.lhd.po.Tag;
import com.lhd.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Created by liuhandong on 2022/4/20.
 */

@RestController
public class TagController {

    @Autowired
    private TagService tagService;

    @PostMapping("/admin/tag/post")
    public Integer postTag(@RequestBody Tag tag){
        if (tag.getId() < 0){
            tag.setId(tagService.getMaxId()+1);
            return tagService.saveTag(tag);
        }else {
            return tagService.updateTag(tag.getId(),tag);
        }
    }

    @GetMapping("/admin/tag/{id}/delete")
    public Long deleteTag(@PathVariable Long id) {
        return tagService.deleteTag(id);
    }

}
